<html>
<head><meta charset="utf-8"><title>check if DefId is in std/core/alloc · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20DefId.20is.20in.20std.2Fcore.2Falloc.html">check if DefId is in std/core/alloc</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="237045619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/check%20if%20DefId%20is%20in%20std/core/alloc/near/237045619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Stu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20DefId.20is.20in.20std.2Fcore.2Falloc.html#237045619">(May 02 2021 at 11:09)</a>:</h4>
<p>Hello <span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span> <br>
If I have a <code>DefId</code>, whats a reliable way to check if the item is defined in <code>std</code>, <code>core</code> or <code>alloc</code>?</p>



<a name="237045707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/check%20if%20DefId%20is%20in%20std/core/alloc/near/237045707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20DefId.20is.20in.20std.2Fcore.2Falloc.html#237045707">(May 02 2021 at 11:11)</a>:</h4>
<p>There is no "reliable" way as none of the crates are hard coded into the compiler. You can estimate it by checking <code>tcx.crate_name(def_id.krate)</code>, but it is possible for a user crate to be named the same as any of these.</p>



<a name="237045797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/check%20if%20DefId%20is%20in%20std/core/alloc/near/237045797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Stu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20DefId.20is.20in.20std.2Fcore.2Falloc.html#237045797">(May 02 2021 at 11:13)</a>:</h4>
<p>Mhh okay. Then I need to use that I guess. Thank you!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>